package 第二章;


public class 希尔排序 {
    public static void main(String[] args) {
        int[] a = {1,4,5,2,9,6,3,8,7,6};
        shellsort(a);
        System.out.println(a);
        
    }
    public static void shellsort(int[] a){
        int n = a.length;
        for(int interval=n/2;interval>0;interval=interval/2){
            for(int i =interval;i<n;i++){
                int target = a[i];
                int j = i-interval;
                while(j>=1&&target<a[j]){
                    a[j+interval] = a[j];
                    j=j-interval;
                }
                a[j+interval] = target;
            }
        }
    }
}
